﻿namespace SLClient.CustomerControls
{
    using System;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Threading;

    public class BetDataControl : INotifyPropertyChanged
    {
        public ObservableCollection<BetData> BetDatas = new ObservableCollection<BetData>();
        private PropertyChangedEventHandler _PropertyChanged;

        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                PropertyChangedEventHandler handler2;
                PropertyChangedEventHandler propertyChanged = this._PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    PropertyChangedEventHandler handler3 = (PropertyChangedEventHandler) Delegate.Combine(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this._PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
            remove
            {
                PropertyChangedEventHandler handler2;
                PropertyChangedEventHandler propertyChanged = this._PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    PropertyChangedEventHandler handler3 = (PropertyChangedEventHandler) Delegate.Remove(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<PropertyChangedEventHandler>(ref this._PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
        }

        public void AddBetData(int betcount, string betdata, double width)
        {
            BetData data2 = new BetData {
                BetCount = betcount,
                Datas = betdata,
                Width = width
            };
            BetData item = data2;
            this.BetDatas.Add(item);
            this.NotifyPropertyChanged("BetCount");
        }

        public void ClearBetData()
        {
            this.BetDatas.Clear();
            this.NotifyPropertyChanged("BetCount");
        }

        public bool ContainsBetData(string data)
        {
            foreach (BetData data2 in this.BetDatas)
            {
                if (data2.Datas == data)
                {
                    return true;
                }
            }
            return false;
        }

        public string GetBetDatas()
        {
            string str = "";
            foreach (BetData data in this.BetDatas)
            {
                str = str + data.Datas + "$";
            }
            if (str.Length > 0)
            {
                str = str.Substring(0, str.Length - 1);
            }
            return str;
        }

        public void NotifyPropertyChanged(string propertyName)
        {
            if (this._PropertyChanged != null)
            {
                this._PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void RemoveBetData(BetData bd)
        {
            if (this.BetDatas.Remove(bd))
            {
                this.NotifyPropertyChanged("BetCount");
            }
        }

        public int BetCount
        {
            get
            {
                int num = 0;
                foreach (BetData data in this.BetDatas)
                {
                    num += data.BetCount;
                }
                return num;
            }
        }
    }
}

